package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TourismPactMapper;
import com.ruoyi.system.domain.TourismPact;
import com.ruoyi.system.service.ITourismPactService;

/**
 * 收藏Service业务层处理
 *
 * @author gqd
 * @date 2020-12-29
 */
@Service
public class TourismPactServiceImpl implements ITourismPactService
{
    @Autowired
    private TourismPactMapper tourismPactMapper;

    /**
     * 查询收藏
     *
     * @param id 收藏ID
     * @return 收藏
     */
    @Override
    public TourismPact selectTourismPactById(Integer id)
    {
        return tourismPactMapper.selectTourismPactById(id);
    }

    /**
     * 查询收藏列表
     *
     * @param tourismPact 收藏
     * @return 收藏
     */
    @Override
    public List<TourismPact> selectTourismPactList(TourismPact tourismPact)
    {
        return tourismPactMapper.selectTourismPactList(tourismPact);
    }

    /**
     * 新增收藏
     *
     * @param tourismPact 收藏
     * @return 结果
     */
    @Override
    public int insertTourismPact(TourismPact tourismPact)
    {
        tourismPact.setCreateTime(DateUtils.getNowDate());
        return tourismPactMapper.insertTourismPact(tourismPact);
    }

    /**
     * 修改收藏
     *
     * @param tourismPact 收藏
     * @return 结果
     */
    @Override
    public int updateTourismPact(TourismPact tourismPact)
    {
        tourismPact.setUpdateTime(DateUtils.getNowDate());
        return tourismPactMapper.updateTourismPact(tourismPact);
    }

    /**
     * 批量删除收藏
     *
     * @param ids 需要删除的收藏ID
     * @return 结果
     */
    @Override
    public int deleteTourismPactByIds(Integer[] ids)
    {
        return tourismPactMapper.deleteTourismPactByIds(ids);
    }

    /**
     * 删除收藏信息
     *
     * @param id 收藏ID
     * @return 结果
     */
    @Override
    public int deleteTourismPactById(Integer id)
    {
        return tourismPactMapper.deleteTourismPactById(id);
    }

    /**
     * 进行收藏
     * @param
     * @return
     */
    @Override
    public AjaxResult insertPact(Integer userId,Integer pactId,Integer pactType) {
        TourismPact tourismPact = tourismPactMapper.selectPactAllId(userId,pactId,pactType);
        if(tourismPact != null){
            return AjaxResult.error("您已收藏！");
        }
        TourismPact tourismPact1 = new TourismPact();
        tourismPact1.setUserId(userId);
        tourismPact1.setPactId(pactId);
        tourismPact1.setPactType(pactType);
        tourismPactMapper.insertTourismPact(tourismPact1);
        return AjaxResult.success("收藏成功！");
    }

    /**
     * 取消收藏
     * @param pactId
     * @param pactType
     * @return
     */
    @Override
    public AjaxResult deletePactId(Integer userId,Integer pactId, Integer pactType) {
        TourismPact tourismPact = tourismPactMapper.selectPactAllId(userId,pactId, pactType);
        if(tourismPact == null){
            return AjaxResult.error("您未收藏！");
        }
        tourismPactMapper.deleteTourismPactById(tourismPact.getId());
        return AjaxResult.success("取消成功！");
    }
}
